<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />

<style type="text/css">
</style>

</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">
					
					<%@ include file="fncGroupCompanyAccountInclude.jsp"%>

				<div class="btnsBox">
					<c:if test="${operate == 'add' ||operate == 'updateAll' || operate == 'updatePart'}">
						<span id="saveBtn" class="sq-button sq-button-round"
							onclick="save();">保存</span>
					</c:if>
					
				</div>
				</div>
			</form>
			<div class="fieldBox col_100" style="display:none;">
				<div class="field">
					 <input name="sysDate" id="sysDate" type="text" class="ui-textbox" value="${sysDate }">
                      <input name="loginUsrNm" id="loginUsrNm" type="text" class="ui-textbox" value="${loginUsrNm }">
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
	 	var operate='${operate}'; 
		$(function() {
			$("#ligerForm").ligerForm({
		        validate : true
		    });
			
			
			//设置省、市
            setRgnProvCdUpdataValue("${fncGroupCompanyAccountVO.bankProv}");
            setRgnCityCdUpdataValue("${fncGroupCompanyAccountVO.bankCity}");
            
            loadFilesLiger("accountData", 2, "${fncGroupCompanyAccountVO.id}", "yes");
            <c:if test="${empty operate || operate == 'view'}">
          		//设置所有不可用
	        	setAllDisabled();
	        	loadFilesLiger("accountData", 2, "${fncGroupCompanyAccountVO.id}", "no");
	        </c:if>
	        
	        
            <c:if test="${operate == 'updatePart'}">
          		//设置"客户经理及联系方式"可用,其他不可用
            	setPartDisabled();
            	 loadFilesLiger("accountData", 2, "${fncGroupCompanyAccountVO.id}", "no");
            </c:if>
            
	    });
		
		//设置"客户经理及联系方式"可用,其他不可用
		function setPartDisabled(){
			liger.get("groupCompanyId").setDisabled(true);
			liger.get("buOrgcd").setDisabled(true);
			liger.get("bank").setDisabled(true);
			liger.get("bankName").setDisabled(true);
			liger.get("bankAddress").setDisabled(true);
			liger.get("currency").setDisabled(true);
			liger.get("bankNature").setDisabled(true);
			liger.get("accountOpenDate").setDisabled(true);
			liger.get("isNetBank").setDisabled(true);
			liger.get("isOnlineAccount").setDisabled(true);
			liger.get("accountCloseDate").setDisabled(true);
			liger.get("bankUse").setDisabled(true);
			liger.get("rgnProvCd").setDisabled(true);
			liger.get("rgnCityCd").setDisabled(true);
			liger.get("bankAccount").setDisabled(true);
			liger.get("corpName").setDisabled(true);//法人姓名
			liger.get("corpPhone").setDisabled(true);//法人预留电话
			liger.get("operName").setDisabled(true);//经办人姓名
			liger.get("operPhone").setDisabled(true);//经办人预留电话
		}
		
		
		function setAllDisabled(){
			setPartDisabled();
			liger.get("cstMgr").setDisabled(true);
		}
		
		function save(){
			
			//验证
			var ligerForm = liger.get("ligerForm");
			if (!ligerForm.valid()) {
			    	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning",SQ_showButtons: true});
		            return ; 
		    }
			 
			
			if(!getRgnProvCd() || !getRgnCityCd()){
				top.$.ligerDialog.SQalert({content: "请选择开户地",SQ_type: "warning"});
				return false;
			}
			
		   
			<c:if test="${operate == 'add' ||operate == 'updateAll'}">
				if (!ligerForm.valid()) {
			    	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning",SQ_showButtons: true});
			            return ; 
			     }
				
				if($.trim($("#groupCompanyId").val()) == ""){
					$.ligerDialog.SQalert({content: "请选择所属集团公司",SQ_type: "warning",SQ_showButtons: true});
					return ;
				}
			</c:if>
		
			
			
			
		   
			//组织数据，提交后台
			var data = ligerForm.getData();
			
			data["id"] = "${fncGroupCompanyAccountVO.id}";
			data["bankProv"] = data.rgnProvCd;//开户地-省
			data["bankCity"] = data.rgnCityCd;//开户地-市
			
			console.log(data);
			//return;
			
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: '<%=path%>/account/fncGroupCompanyAccount/save.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : LogUtils.LOG_CMM_DATA_LOADING,
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						if(operate=='updatePart'){
						}else{
							saveFile2(msg.data);
						}
						//$.ligerDialog.SQalert({content: msg.info,SQ_type: "success",SQ_showButtons: true});
						alert(msg.info);
						Remove_navTab();//关闭当前页面
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					wait_dialog.close();
					$.ligerDialog.SQalert({
						content : "网络错误，请稍后重试",
						SQ_type : "error"
					});
				}
			});
		}
		//保存文件
		function saveFile2(pkId){
			var docArray = JSON.stringify(getUploadResultParams(2));
	        var url = "<%=path%>/rfcont/fncPrjContAudit/uploadAttchment.do";
        	if(null == docArray){
        		//无要上传的文件-直接结束
        		//top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
        	}else{
		        if(pkId){//ID不为空执行
			        //赋值附件
			        var data = {
						"docArray":docArray,
						"pkId": pkId,
						"flag": "accountData"
					};
					//请求
			        AjaxUtils.ajaxPost(url, data, function(msg){
			        	if(msg.success == 1){
							 //top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
							 if(msg.data){
								 clearUploadResultParams(2);
							 }
						 }else{
							 UIUtils.alertError(msg.info);
						 }
			        }, true);
		        }else{
		        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
		        }
        	}
		}
		//显示已上传但是未保存的文件列表
		function showFiles(data, index){
			var sysDate = $("#sysDate").val();
			var loginUsrNm = $("#loginUsrNm").val();
			var f_Grid = liger.get("ligergrid_file"+index);
			var uploadJOSN = data;
    		for (var i=0; i< uploadJOSN.length; i++){ 
        		//添加行-追加行
        		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index, id: i});
    		}
		}
	</script>
</body>
</html>